package com.frx.sort.insertsort;

import java.util.Arrays;

/**
 * Created with IDEA
 *
 * @author: xrf
 * @Date: 2019/10/24
 * @Time: 20:58
 */
public class TestOne {

    public static void main(String[] args){
        int[] arr = {2,3,5,1,6,4};
        insertSort(arr);
        System.out.println(Arrays.toString(arr));

    }
    public static void insertSort(int[] arr){
        for (int i=1;i<arr.length;i++){
            int val = arr[i];
            int j = i-1;
            for (;j>=0;j--){
                if (arr[j] > val){
                    arr[j+1] = arr[j];
                } else {
                    break;
                }
            }
            arr[j+1] = val;

        }
    }

}
